package backend.majiong.yaku;

import java.util.ArrayList;
import java.util.List;

import backend.MainGame;
import backend.majiong.Combo;
import backend.majiong.ComboPai;
import backend.majiong.Pai;
import backend.majiong.Player;

public class HandCombo {

    private List<Pai> anSunZi = new ArrayList<Pai>();

    private List<Pai> anKeZi = new ArrayList<Pai>();

    private Pai duiZi;

    private List<Pai> mingShun = new ArrayList<Pai>();

    private List<Pai> mingKe = new ArrayList<Pai>();

    private List<Pai> daMingGang = new ArrayList<Pai>();

    private List<Pai> anGang = new ArrayList<Pai>();

    private List<Pai> jiaGang = new ArrayList<Pai>();

    private List<Pai> allHandPai = new ArrayList<Pai>();

    private List<Pai> fuluMianzi = new ArrayList<Pai>();

    private List<Pai> shouMianzi = new ArrayList<Pai>();

    private List<Pai> shunzi = new ArrayList<Pai>();

    private List<Pai> kezi = new ArrayList<Pai>();

    private List<Pai> gangzi = new ArrayList<Pai>();

    private List<Pai> mianzi = new ArrayList<Pai>();
    
    private Pai addPai;

    private Pai selfWind;

    private Pai tableWind;
    
    private SpecialYakuFlag yakuFlag;

    public static HandCombo buildHandCombo(Player player, Combo combo, MainGame mainGame) {
        HandCombo hc = new HandCombo();
        hc.duiZi = combo.getDuiZi();
        hc.anSunZi.addAll(combo.getSunZi());
        hc.anKeZi.addAll(combo.getKeZi());
        hc.yakuFlag = player.getSpecialYakuFlag();
        hc.addPai = player.getHandPai().getAddPai();
        for (ComboPai cp : player.getHandPai().getFulu()) {
            switch (cp.getType()) {
                case ComboPai.TYPE_ANKAN:
                    hc.anGang.add(cp.getPaiList().get(0));
                    break;
                case ComboPai.TYPE_DAIMINKAN:
                    hc.daMingGang.add(cp.getPaiList().get(0));
                    break;
                case ComboPai.TYPE_KAKAN:
                    hc.jiaGang.add(cp.getPaiList().get(0));
                    break;
                case ComboPai.TYPE_MINKOU:
                    hc.mingKe.add(cp.getPaiList().get(0));
                    break;
                case ComboPai.TYPE_MINSHUN:
                    hc.mingShun.add(cp.getPaiList().get(0));
                    break;
            }
        }
        hc.fuluMianzi.addAll(hc.daMingGang);
        hc.fuluMianzi.addAll(hc.jiaGang);
        hc.fuluMianzi.addAll(hc.mingKe);
        hc.fuluMianzi.addAll(hc.mingShun);

        hc.shouMianzi.addAll(hc.anGang);
        hc.shouMianzi.addAll(hc.anKeZi);
        hc.shouMianzi.addAll(hc.anSunZi);

        hc.shunzi.addAll(hc.anSunZi);
        hc.shunzi.addAll(hc.mingShun);

        hc.kezi.addAll(hc.anKeZi);
        hc.kezi.addAll(hc.mingKe);

        hc.gangzi.addAll(hc.daMingGang);
        hc.gangzi.addAll(hc.jiaGang);
        hc.gangzi.addAll(hc.anGang);

        hc.mianzi.addAll(hc.fuluMianzi);
        hc.mianzi.addAll(hc.shouMianzi);

        hc.allHandPai.addAll(player.getHandPai().getAllHandPai());
        return hc;
    }

    public List<Pai> getAnSunZi() {
        return anSunZi;
    }

    public List<Pai> getAnKeZi() {
        return anKeZi;
    }

    public Pai getDuiZi() {
        return duiZi;
    }

    public List<Pai> getMingShun() {
        return mingShun;
    }

    public List<Pai> getMingKe() {
        return mingKe;
    }

    public List<Pai> getDaMingGang() {
        return daMingGang;
    }

    public List<Pai> getAnGang() {
        return anGang;
    }

    public List<Pai> getJiaGang() {
        return jiaGang;
    }

    public List<Pai> getAllHandPai() {
        return allHandPai;
    }

    public List<Pai> getFuluMianzi() {
        return fuluMianzi;
    }

    public List<Pai> getShouMianzi() {
        return shouMianzi;
    }

    public List<Pai> getSunZi() {
        return shunzi;
    }

    public List<Pai> getKeZi() {
        return kezi;
    }

    public List<Pai> getGangZi() {
        return gangzi;
    }

    public List<Pai> getMianzi() {
        return mianzi;
    }

    public SpecialYakuFlag getSpecialYakuFlag() {
        return this.yakuFlag;
    }

    public Pai getAddPai() {
        return addPai;
    }
    
    public boolean getIsMengQing(){
        List<Pai> fuluPais = getFuluMianzi();
        if (fuluPais.size() > 0) {
            return false;
        }
        return true;
    }

    public void setSelfWind(Pai selfWind) {
        this.selfWind = selfWind;
    }

    public Pai getSelfWind() {
        return selfWind;
    }

    public void setTableWind(Pai tableWind) {
        this.tableWind = tableWind;
    }

    public Pai getTableWind() {
        return tableWind;
    }

}
